Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nix: prepare targets with rust-overlay #57

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

hellodword
Copy link
Contributor

pre-install the system-images
add doc of using avd without android-studio

pre-install the system-images
add doc of using avd without android-studio
(lib.optionals (stdenv.isLinux && stdenv.isx86_64) [
"x86_64-unknown-linux-gnu"
]) ++
(lib.optionals (stdenv.isLinux && !stdenv.isx86_64) [
Copy link
Contributor Author

@hellodword hellodword May 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jb55 could you review this on the darwin and aarch64 linux? I'm simply following the rustup target list, I guess they're in the right way but I'm not sure

      (lib.optionals (stdenv.isLinux && !stdenv.isx86_64) [
        "aarch64-unknown-linux-gnu"
      ]) ++
      (lib.optionals (stdenv.isDarwin && stdenv.isx86_64) [
        "x86_64-apple-darwin"
      ]) ++
      (lib.optionals (stdenv.isDarwin && !stdenv.isx86_64) [
        "aarch64-apple-darwin"
      ])

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can test on darwin, I think @kernelkind has an aarch64 linux machine.

@jb55
Copy link
Contributor

jb55 commented May 16, 2024

does cargo-apk work with this? we were relying on rustup for cross compiling to android

@hellodword hellodword mentioned this pull request May 17, 2024
@hellodword
Copy link
Contributor Author

does cargo-apk work with this? we were relying on rustup for cross compiling to android

Yeah, works for me, tested on x86_64 Linux:

RUST_LOG=debug cargo apk build

RUST_LOG=debug cargo apk build --target aarch64-linux-android

# `--arg android_emulator true` required
RUST_LOG=debug cargo apk build --target x86_64-linux-android

@kernelkind
Copy link
Member

[nix-shell:~/Documents/GitRemotes/damus-android]$ rustup target add aarch64-linux-android
info: component 'rust-std' for target 'aarch64-linux-android' is up to date

[nix-shell:~/Documents/GitRemotes/damus-android]$ cargo apk run --release
Using package `notedeck` in `/Users/[redacted]/Documents/GitRemotes/damus-android/Cargo.toml`
Warning: Environment variable ANDROID_SDK_ROOT is deprecated (https://developer.android.com/studio/command-line/variables#envar). It will be used until it is unset and replaced by ANDROID_HOME.
   Compiling cfg-if v1.0.0
   Compiling log v0.4.20
   Compiling once_cell v1.19.0
   Compiling libc v0.2.153
   Compiling scopeguard v1.2.0
   Compiling memchr v2.7.1
   Compiling bytes v1.5.0
   Compiling ring v0.17.7
   Compiling serde v1.0.196
   Compiling generic-array v0.14.7
error[E0463]: can't find crate for `std`
  |
  = note: the `aarch64-linux-android` target may not be installed
  = help: consider downloading the target with `rustup target add aarch64-linux-android`
  = help: consider building the standard library from source with `cargo build -Zbuild-std`

error[E0463]: can't find crate for `core`
  |
  = note: the `aarch64-linux-android` target may not be installed
  = help: consider downloading the target with `rustup target add aarch64-linux-android`
  = help: consider building the standard library from source with `cargo build -Zbuild-std`

For more information about this error, try `rustc --explain E0463`.
error: could not compile `scopeguard` (lib) due to 1 previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `cfg-if` (lib) due to 1 previous error
error: could not compile `once_cell` (lib) due to 1 previous error
error: could not compile `bytes` (lib) due to 1 previous error
error: could not compile `log` (lib) due to 1 previous error
error: could not compile `memchr` (lib) due to 1 previous error
error: could not compile `libc` (lib) due to 1 previous error
error: could not compile `serde` (lib) due to 1 previous error
Error: Command `AR_aarch64-linux-android=/nix/store/hsckmq4g1y2252icajh4q2n4hbckwn88-android-sdk-env/share/android-sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-ar CARGO_ENCODED_RUSTFLAGS=-Clink-arg=--target=aarch64-linux-android23\u{1f}-L\u{1f}/Users/[redacted]/Documents/GitRemotes/damus-android/target/cargo-apk-temp-extra-link-libraries CARGO_TARGET_AARCH64_LINUX_ANDROID_AR=/nix/store/hsckmq4g1y2252icajh4q2n4hbckwn88-android-sdk-env/share/android-sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-ar CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER=/nix/store/hsckmq4g1y2252icajh4q2n4hbckwn88-android-sdk-env/share/android-sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang CC_aarch64-linux-android=/nix/store/hsckmq4g1y2252icajh4q2n4hbckwn88-android-sdk-env/share/android-sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang CFLAGS_aarch64-linux-android=--target=aarch64-linux-android23 CXXFLAGS_aarch64-linux-android=--target=aarch64-linux-android23 CXX_aarch64-linux-android=/nix/store/hsckmq4g1y2252icajh4q2n4hbckwn88-android-sdk-env/share/android-sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ cargo build --target aarch64-linux-android --release` had a non-zero exit code.

@jb55
Copy link
Contributor

jb55 commented May 17, 2024

@kernelkind I think the point of this is that we wouldn't use rustup at least for fetching the compiler? can you try with just a nix shell?

@hellodword
Copy link
Contributor Author

I confirmed it on an aarch64 linux cloud server, it's working:

root@nix-test-arm:~# git clone -b patch-2 https://github.com/hellodword/notedeck && cd notedeck
root@nix-test-arm:~/notedeck# nix-shell 

[nix-shell:~/notedeck]# cargo build
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 2m 11s

[nix-shell:~/notedeck]# echo $?
0

[nix-shell:~/notedeck]# file target/debug/notedeck
target/debug/notedeck: ELF 64-bit LSB pie executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /nix/store/j4pprbyxslahv9lc3mdr6y2pa1xyghdp-glibc-2.39-31/lib/ld-linux-aarch64.so.1, for GNU/Linux 3.10.0, with debug_info, not stripped

@hellodword
Copy link
Contributor Author

hellodword commented May 18, 2024

But the cargo apk build fails, there's a related issue tadfisher/android-nixpkgs#50 , and it's an existing issue for master branch:

(/nix/store/n0mlzi96rg8p35zkndgf8cvnr9xxmipi-android-sdk-env/share/android-sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/bin/clang)

Caused by:
  process didn't exit successfully: `/root/notedeck/target/debug/build/ring-c8f5710186c61e64/build-script-build` (exit status: 1)
  --- stdout
  cargo:rerun-if-env-changed=RING_PREGENERATE_ASM
  cargo:rustc-env=RING_CORE_PREFIX=ring_core_0_17_7_
  OPT_LEVEL = Some("0")
  TARGET = Some("aarch64-linux-android")
  HOST = Some("aarch64-unknown-linux-gnu")
  cargo:rerun-if-env-changed=CC_aarch64-linux-android
  CC_aarch64-linux-android = Some("/nix/store/n0mlzi96rg8p35zkndgf8cvnr9xxmipi-android-sdk-env/share/android-sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/bin/clang")
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("true")
  cargo:rerun-if-env-changed=CFLAGS_aarch64-linux-android
  CFLAGS_aarch64-linux-android = Some("--target=aarch64-linux-android23")
  running: "/nix/store/n0mlzi96rg8p35zkndgf8cvnr9xxmipi-android-sdk-env/share/android-sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/bin/clang" "-O0" "-DANDROID" "-ffunction-sections" "-fdata-sections" "-fPIC" "-gdwarf-2" "-fno-omit-frame-pointer" "--target=aarch64-linux-android" "--target=aarch64-linux-android23" "-I" "include" "-I" "/root/notedeck/target/aarch64-linux-android/debug/build/ring-925c723764f6ea9b/out" "-fvisibility=hidden" "-std=c1x" "-pedantic" "-Wall" "-Wextra" "-Wbad-function-cast" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wenum-compare" "-Wfloat-equal" "-Wformat=2" "-Winline" "-Winvalid-pch" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wnested-externs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wsign-conversion" "-Wstrict-prototypes" "-Wundef" "-Wuninitialized" "-Wwrite-strings" "-g3" "-DNDEBUG" "-o" "/root/notedeck/target/aarch64-linux-android/debug/build/ring-925c723764f6ea9b/out/crypto/curve25519/curve25519.o" "-c" "crypto/curve25519/curve25519.c"

  --- stderr


  error occurred: Command "/nix/store/n0mlzi96rg8p35zkndgf8cvnr9xxmipi-android-sdk-env/share/android-sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/bin/clang" "-O0" "-DANDROID" "-ffunction-sections" "-fdata-sections" "-fPIC" "-gdwarf-2" "-fno-omit-frame-pointer" "--target=aarch64-linux-android" "--target=aarch64-linux-android23" "-I" "include" "-I" "/root/notedeck/target/aarch64-linux-android/debug/build/ring-925c723764f6ea9b/out" "-fvisibility=hidden" "-std=c1x" "-pedantic" "-Wall" "-Wextra" "-Wbad-function-cast" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wenum-compare" "-Wfloat-equal" "-Wformat=2" "-Winline" "-Winvalid-pch" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wnested-externs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wsign-conversion" "-Wstrict-prototypes" "-Wundef" "-Wuninitialized" "-Wwrite-strings" "-g3" "-DNDEBUG" "-o" "/root/notedeck/target/aarch64-linux-android/debug/build/ring-925c723764f6ea9b/out/crypto/curve25519/curve25519.o" "-c" "crypto/curve25519/curve25519.c" with args "clang" failed to start: Os { code: 8, kind: Uncategorized, message: "Exec format error" }


Error: Command `AR_aarch64-linux-android=/nix/store/n0mlzi96rg8p35zkndgf8cvnr9xxmipi-android-sdk-env/share/android-sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar CARGO_ENCODED_RUSTFLAGS=-Clink-arg=--target=aarch64-linux-android23\u{1f}-L\u{1f}/root/notedeck/target/cargo-apk-temp-extra-link-libraries CARGO_TARGET_AARCH64_LINUX_ANDROID_AR=/nix/store/n0mlzi96rg8p35zkndgf8cvnr9xxmipi-android-sdk-env/share/android-sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER=/nix/store/n0mlzi96rg8p35zkndgf8cvnr9xxmipi-android-sdk-env/share/android-sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/bin/clang CC_aarch64-linux-android=/nix/store/n0mlzi96rg8p35zkndgf8cvnr9xxmipi-android-sdk-env/share/android-sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/bin/clang CFLAGS_aarch64-linux-android=--target=aarch64-linux-android23 CXXFLAGS_aarch64-linux-android=--target=aarch64-linux-android23 CXX_aarch64-linux-android=/nix/store/n0mlzi96rg8p35zkndgf8cvnr9xxmipi-android-sdk-env/share/android-sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ cargo check --target aarch64-linux-android` had a non-zero exit code.

And for the master branch:

root@nix-test-arm:~# git clone https://github.com/damus-io/notedeck notedeck2 && cd notedeck2
root@nix-test-arm:~/notedeck2# nix-shell 

[nix-shell:~/notedeck2]# rustup target add aarch64-linux-android
[nix-shell:~/notedeck2]# cargo apk check

Caused by:
  process didn't exit successfully: `/root/notedeck2/target/debug/build/ring-c8f5710186c61e64/build-script-build` (exit status: 1)
  --- stdout
  cargo:rerun-if-env-changed=RING_PREGENERATE_ASM
  cargo:rustc-env=RING_CORE_PREFIX=ring_core_0_17_7_
  OPT_LEVEL = Some("0")
  TARGET = Some("aarch64-linux-android")
  HOST = Some("aarch64-unknown-linux-gnu")
  cargo:rerun-if-env-changed=CC_aarch64-linux-android
  CC_aarch64-linux-android = Some("/nix/store/n0mlzi96rg8p35zkndgf8cvnr9xxmipi-android-sdk-env/share/android-sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/bin/clang")
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("true")
  cargo:rerun-if-env-changed=CFLAGS_aarch64-linux-android
  CFLAGS_aarch64-linux-android = Some("--target=aarch64-linux-android23")
  running: "/nix/store/n0mlzi96rg8p35zkndgf8cvnr9xxmipi-android-sdk-env/share/android-sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/bin/clang" "-O0" "-DANDROID" "-ffunction-sections" "-fdata-sections" "-fPIC" "-gdwarf-2" "-fno-omit-frame-pointer" "--target=aarch64-linux-android" "--target=aarch64-linux-android23" "-I" "include" "-I" "/root/notedeck2/target/aarch64-linux-android/debug/build/ring-925c723764f6ea9b/out" "-fvisibility=hidden" "-std=c1x" "-pedantic" "-Wall" "-Wextra" "-Wbad-function-cast" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wenum-compare" "-Wfloat-equal" "-Wformat=2" "-Winline" "-Winvalid-pch" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wnested-externs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wsign-conversion" "-Wstrict-prototypes" "-Wundef" "-Wuninitialized" "-Wwrite-strings" "-g3" "-DNDEBUG" "-o" "/root/notedeck2/target/aarch64-linux-android/debug/build/ring-925c723764f6ea9b/out/crypto/curve25519/curve25519.o" "-c" "crypto/curve25519/curve25519.c"

  --- stderr


  error occurred: Command "/nix/store/n0mlzi96rg8p35zkndgf8cvnr9xxmipi-android-sdk-env/share/android-sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/bin/clang" "-O0" "-DANDROID" "-ffunction-sections" "-fdata-sections" "-fPIC" "-gdwarf-2" "-fno-omit-frame-pointer" "--target=aarch64-linux-android" "--target=aarch64-linux-android23" "-I" "include" "-I" "/root/notedeck2/target/aarch64-linux-android/debug/build/ring-925c723764f6ea9b/out" "-fvisibility=hidden" "-std=c1x" "-pedantic" "-Wall" "-Wextra" "-Wbad-function-cast" "-Wcast-align" "-Wcast-qual" "-Wconversion" "-Wenum-compare" "-Wfloat-equal" "-Wformat=2" "-Winline" "-Winvalid-pch" "-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wnested-externs" "-Wredundant-decls" "-Wshadow" "-Wsign-compare" "-Wsign-conversion" "-Wstrict-prototypes" "-Wundef" "-Wuninitialized" "-Wwrite-strings" "-g3" "-DNDEBUG" "-o" "/root/notedeck2/target/aarch64-linux-android/debug/build/ring-925c723764f6ea9b/out/crypto/curve25519/curve25519.o" "-c" "crypto/curve25519/curve25519.c" with args "clang" failed to start: Os { code: 8, kind: Uncategorized, message: "Exec format error" }


Error: Command `AR_aarch64-linux-android=/nix/store/n0mlzi96rg8p35zkndgf8cvnr9xxmipi-android-sdk-env/share/android-sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar CARGO_ENCODED_RUSTFLAGS=-Clink-arg=--target=aarch64-linux-android23\u{1f}-L\u{1f}/root/notedeck2/target/cargo-apk-temp-extra-link-libraries CARGO_TARGET_AARCH64_LINUX_ANDROID_AR=/nix/store/n0mlzi96rg8p35zkndgf8cvnr9xxmipi-android-sdk-env/share/android-sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER=/nix/store/n0mlzi96rg8p35zkndgf8cvnr9xxmipi-android-sdk-env/share/android-sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/bin/clang CC_aarch64-linux-android=/nix/store/n0mlzi96rg8p35zkndgf8cvnr9xxmipi-android-sdk-env/share/android-sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/bin/clang CFLAGS_aarch64-linux-android=--target=aarch64-linux-android23 CXXFLAGS_aarch64-linux-android=--target=aarch64-linux-android23 CXX_aarch64-linux-android=/nix/store/n0mlzi96rg8p35zkndgf8cvnr9xxmipi-android-sdk-env/share/android-sdk/ndk/24.0.8215888/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ cargo check --target aarch64-linux-android` had a non-zero exit code.

@hellodword
Copy link
Contributor Author

I'll draft this and try to achieve:

  • compatible with both Nix flakes and legacy Nix command
  • minimize dependencies for all platforms
  • make cargo-apk happy on aarch64 linux

@hellodword hellodword marked this pull request as draft May 22, 2024 01:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants